import FingerprintJS from '@fingerprintjs/fingerprintjs';

const SESSION_FINGERPRINT = 'x-device-fingerprint';

/**
 * 设备指纹生成
 */
export const initDeviceFingerprint = async () => {
    const fp = await FingerprintJS.load();
    const result = await fp.get();
    localStorage.setItem(SESSION_FINGERPRINT, result.visitorId);
};

/**
 * 获取设备指纹
 */
export const getFingerprint = (): string => {
    const visitorId = localStorage.getItem(SESSION_FINGERPRINT);
    if (!visitorId) {
        return '';
    }
    return visitorId.toString();
};